﻿#include "ImageItem.h"
#include <QDebug>
#include <QGraphicsSceneHoverEvent>
#include <QLineEdit>
#include <QGraphicsProxyWidget>

ImageItem::ImageItem(QWidget *parent) : QGraphicsPixmapItem(nullptr)
{

//    QLineEdit *lineEdit = new QLineEdit("Hello");
//    QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
//    proxy->setWidget(lineEdit);

}

void ImageItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{

    QPointF mousePosition = event->pos();
    //在图片范围内
    if(mousePosition.x()>0&&mousePosition.x()<pixmap().width()&&mousePosition.y()>0&&mousePosition.y()<pixmap().height())
    {
        int R,G,B;
        pixmap().toImage().pixelColor(mousePosition.x(), mousePosition.y()).getRgb(&R,&G,&B);

        QString InfoVal=QString("[%1 %2 %3]\n{X%4 Y%5}").arg(QString::number(R),3,' ')
                .arg(QString::number(G),3,' ')
                .arg(QString::number(B),3,' ')
                .arg(QString::number((int)mousePosition.x()),4,' ')
                .arg(QString::number((int)mousePosition.y()),4,' ');
        emit RGBValue(InfoVal);
    }

}



